'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.genProgressFixSimple = exports.genProgressFix = undefined;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _isNaN = require('lodash/isNaN');

var _isNaN2 = _interopRequireDefault(_isNaN);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var ProgressFix = function () {
    function ProgressFix() {
        (0, _classCallCheck3.default)(this, ProgressFix);
        this.oldProgress = 0;
        this.delta = 1;
        this.fixed = 2;
    }

    (0, _createClass3.default)(ProgressFix, [{
        key: 'fixSimple',
        value: function fixSimple(progress) {
            if (typeof progress === 'number' && !(0, _isNaN2.default)(progress)) {
                var _progress = Math.abs(progress);
                _progress = Math.floor(_progress < 1 ? _progress * 100 : _progress);
                this.oldProgress = _progress;
            }
            return this.oldProgress;
        }
    }, {
        key: 'fix',
        value: function fix(progress) {
            var oldProgress = this.oldProgress,
                delta = this.delta,
                fixed = this.fixed;

            var _progress = this.fixSimple(progress);
            if (_progress > oldProgress) {
                this.oldProgress = _progress;
            } else if (_progress < oldProgress) {
                _progress = oldProgress + delta > 98 ? 98 : oldProgress + delta;
                this.oldProgress = _progress;
            }
            return this.oldProgress.toFixed(fixed);
        }
    }]);
    return ProgressFix;
}();

var genProgressFix = exports.genProgressFix = function genProgressFix() {
    var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        _ref$delta = _ref.delta,
        delta = _ref$delta === undefined ? 1 : _ref$delta,
        _ref$fixed = _ref.fixed,
        fixed = _ref$fixed === undefined ? 1 : _ref$fixed;

    var progressFix = new ProgressFix();
    progressFix.delta = delta;
    progressFix.fixed = fixed;
    return function (progress) {
        return progressFix.fix(progress);
    };
};
var genProgressFixSimple = exports.genProgressFixSimple = function genProgressFixSimple() {
    var progressFix = new ProgressFix();
    return function (progress) {
        return progressFix.fixSimple(progress);
    };
};
exports.default = genProgressFix;